﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;

namespace lp1415_5605
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        /// <summary>
        /// Objecto responsavel por ler e armazenar o conteudo da Base de Dados.
        /// </summary>
        private GetDataDb table_data = null;

        /// <summary>
        /// Objecto responsável por mostrar as estatisticas
        /// </summary>
        private PlotStatistics ploStats = null;

        /// <summary>
        /// MainWindow Constructor
        /// Se já existir uma base de dados, os dados são carregados e as comboBox's são preenchidas com o anos lidos.
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();

            if (File.Exists("Dados.db"))
            {
                this.table_data = new GetDataDb("Dados.db");
                this.ploStats = new PlotStatistics(table_data);

                initializeComboBoxs();
            }
        }

        /// <summary>
        /// Preenche as comboBox's com os anos lidos na Base de Dados.
        /// </summary>
        private void initializeComboBoxs()
        {
            foreach (String ano in this.table_data.getYears())
            {
                this.cmbFirstYear.Items.Add(ano);
                this.cmbLastYear.Items.Add(ano);
            }
            this.cmbFirstYear.SelectedIndex = 0;
            this.cmbLastYear.SelectedIndex = 0;
        }

        /// <summary>
        /// Cria uma Base de Dados SQLite3 com base no conteúdo de um ficheiro de Excel
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCreateDb_Click(object sender, RoutedEventArgs e)
        {
            new DadosTabela().createDb("Dados.db");
            this.table_data = new GetDataDb("Dados.db");
            this.ploStats = new PlotStatistics(table_data);

            initializeComboBoxs();
        }

        /// <summary>
        /// Mostra a estatistica sobre o IPC
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnIPC_Click(object sender, RoutedEventArgs e)
        {
            this.ploStats.getStat((string)this.btnIPC.Content, 1, Convert.ToInt32(this.cmbFirstYear.SelectedValue), Convert.ToInt32(this.cmbLastYear.SelectedValue));
        }

        /// <summary>
        /// Mostra a estatistica sobre a Taxa de Inflação
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnInflateRate_Click(object sender, RoutedEventArgs e)
        {
            this.ploStats.getStat((string)this.btnInflateRate.Content, 2, Convert.ToInt32(this.cmbFirstYear.SelectedValue), Convert.ToInt32(this.cmbLastYear.SelectedValue));
        }

        /// <summary>
        /// Mostra a estatistica sobre a Remuneração Minima Mensal
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnMinimumMonthlyPay_Click(object sender, RoutedEventArgs e)
        {
            this.ploStats.getStat((string)this.btnMinimumMonthlyPay.Content, 3, Convert.ToInt32(this.cmbFirstYear.SelectedValue), Convert.ToInt32(this.cmbLastYear.SelectedValue));
        }

        /// <summary>
        /// Mostra a estatistica sobre a Remuneração Máxima Mensal
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnMaximumMonthlyPay_Click(object sender, RoutedEventArgs e)
        {
            this.ploStats.getStat((string)this.btnMaximumMonthlyPay.Content, 4, Convert.ToInt32(this.cmbFirstYear.SelectedValue), Convert.ToInt32(this.cmbLastYear.SelectedValue));
        }

        /// <summary>
        /// Mostra a estatistica sobre a Remuneração Minima e Máxima Mensal
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnMinMaxMonthlyPay_Click(object sender, RoutedEventArgs e)
        {
            this.ploStats.getStat((string)this.btnMinimumMonthlyPay.Content, (string)this.btnMaximumMonthlyPay.Content, 3, 4, Convert.ToInt32(this.cmbFirstYear.SelectedValue), Convert.ToInt32(this.cmbLastYear.SelectedValue));
        }

        /// <summary>
        /// Mostra a estatistica PIB per Capita
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnPibPerCapita_Click(object sender, RoutedEventArgs e)
        {
            this.ploStats.getStat((string)this.btnPibPerCapita.Content, 5, Convert.ToInt32(this.cmbFirstYear.SelectedValue), Convert.ToInt32(this.cmbLastYear.SelectedValue));
        }

        /// <summary>
        /// Mostra a estatistica RNB per Capita
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnRnbPerCapita_Click(object sender, RoutedEventArgs e)
        {
            this.ploStats.getStat((string)this.btnRnbPerCapita.Content, 6, Convert.ToInt32(this.cmbFirstYear.SelectedValue), Convert.ToInt32(this.cmbLastYear.SelectedValue));
        }

        /// <summary>
        /// Mostra a estatistica RDB per Capita
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnRdbPerCapita_Click(object sender, RoutedEventArgs e)
        {
            this.ploStats.getStat((string)this.btnRdbPerCapita.Content, 7, Convert.ToInt32(this.cmbFirstYear.SelectedValue), Convert.ToInt32(this.cmbLastYear.SelectedValue));
        }

        /// <summary>
        /// Mostra a estatistica Remunerações per Capita Anuais
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCapitalAnnualRemuneration_Click(object sender, RoutedEventArgs e)
        {
            this.ploStats.getStat((string)this.btnCapitalAnnualRemuneration.Content, 8, Convert.ToInt32(this.cmbFirstYear.SelectedValue), Convert.ToInt32(this.cmbLastYear.SelectedValue));
        }
    }
}